package com.baofu.paycore.service.facade.enums;

import com.system.commons.exception.BizServiceException;
import com.system.commons.exception.CommonErrorCode;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

/**
 * 预授权确认模式
 *
 * User: xin deng  Date: 16/9/1 ProjectName: paycore Version: 1.0
 */
@Slf4j
@Getter
@AllArgsConstructor
public enum AuthConfirmModeEnum {

    HOLD("HOLD", "剩余金额不释放"),

    RELEASE("RELEASE", "剩余金额释放");

    private String code;

    private String desc;

    /**
     * 通过枚举编码获得枚举
     *
     * @param code    枚举编码
     * @return        返回编码对应的枚举类型
     */
    public static AuthConfirmModeEnum explain(String code) {
        for (AuthConfirmModeEnum authConfirmModeEnum : values()) {
            if (authConfirmModeEnum.getCode().equals(code)) {
                return authConfirmModeEnum;
            }
        }
        log.error("不支持预授权确认模式类型:{}", code);
        throw new BizServiceException(CommonErrorCode.VALUE_NOT_SUPPORT, "不支持预授权确认模式类型");
    }
}

